package com.bright.hxj.qchz.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bright.hxj.qchz.mapper.CommonMapper;
import com.bright.hxj.qchz.mapper.Duijie_ShiJieShouDeploy_TablepanaMapper;
import com.bright.hxj.qchz.pojo.po.Duijie_ShiJieShouDeploy_TablePana;
import com.bright.hxj.qchz.service.Duijie_ShiJieShouDeploy_TablePanaManager;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List; /**
 * @Author hxj
 * @Date 2025/2/7 17:37
 * @Description
 */
@Service
@RequiredArgsConstructor
@DS("datasource-shiJieShou")
public class Duijie_ShiJieShouDeploy_TablePanaManagerImpl extends ServiceImpl<Duijie_ShiJieShouDeploy_TablepanaMapper, Duijie_ShiJieShouDeploy_TablePana> implements Duijie_ShiJieShouDeploy_TablePanaManager {

    private final CommonMapper commonMapper;

    @Override
    public List<Duijie_ShiJieShouDeploy_TablePana> getTablePanas(String tname) {
//        String sql = "SELECT id, tname, tcolumn, tdescription, ttype, islist, listSql, torder, tisedit, tdefault, visible, " +
//                "isMust, isMainKey, maxLength FROM Duijie_JieShou_Deploy_TablePana WHERE tname=? AND visible=1 order by torder, id";
        List<Duijie_ShiJieShouDeploy_TablePana> list = list(new LambdaQueryWrapper<Duijie_ShiJieShouDeploy_TablePana>()
                .eq(Duijie_ShiJieShouDeploy_TablePana::getTname, tname)
                .eq(Duijie_ShiJieShouDeploy_TablePana::getVisible, true)
                .orderByAsc(Duijie_ShiJieShouDeploy_TablePana::getTorder)
                .orderByAsc(Duijie_ShiJieShouDeploy_TablePana::getId));

        for (Duijie_ShiJieShouDeploy_TablePana tablePana : list) {
            if(tablePana.getIsList()) {
                String sql = tablePana.getListSql();

                // TODO 下拉列表的情况 commonMapper加了自定义语句的方法 但查出来是List<Map> 要转成List<List>
//                tablePana.setLists(commonMapper.selectByFullSql(sql, null));
            }
        }

        return list;
    }
}
